﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_hoadon_nguyenlieuInfo
    {
        private int _id_nguyenlieu;
        private int _id_hoadon;
        private double _soluong;
        private double _dongia;
        private double _conlai;
        private int _trangthai;
        private string _ghichu;

        public cs_erp_hoadon_nguyenlieuInfo()
        {
            this._id_nguyenlieu = 0;
            this._id_hoadon = 0;
            this._soluong = 0;
            this._dongia = 0;
            this._conlai = 0;
            this._trangthai = 0;
            this._ghichu = " ";

        }
        public int id_nguyenlieu
        {
            get
            {
                return this._id_nguyenlieu;
            }
            set
            {
                this._id_nguyenlieu = value;
            }
        }
        public int id_hoadon
        {
            get
            {
                return this._id_hoadon;
            }
            set
            {
                this._id_hoadon = value;
            }
        }
        public double soluong
        {
            get
            {
                return this._soluong;
            }
            set
            {
                this._soluong = value;
            }
        }
        public double dongia
        {
            get
            {
                return this._dongia;
            }
            set
            {
                this._dongia = value;
            }
        }
        public double conlai
        {
            get
            {
                return this._conlai;
            }
            set
            {
                this._conlai = value;
            }
        }
        public int trangthai
        {
            get
            {
                return this._trangthai;
            }
            set
            {
                this._trangthai = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[8];
            paraName[0] = "@id_nguyenlieu";
            paraName[1] = "@id_hoadon";
            paraName[2] = "@soluong";
            paraName[3] = "@dongia";
            paraName[4] = "@conlai";
            paraName[5] = "@trangthai";
            paraName[6] = "@ghichu";
            paraName[7] = "@option";
            object[] paraValue = new object[8];
            paraValue[0] = this._id_nguyenlieu;
            paraValue[1] = this._id_hoadon;
            paraValue[2] = this._soluong;
            paraValue[3] = this._dongia;
            paraValue[4] = this._conlai;
            paraValue[5] = this._trangthai;
            paraValue[6] = this._ghichu;
            paraValue[7] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 8, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_HOADON_NGUYENLIEU", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("id_hoadon", "id_nguyenlieu");
            cb.KetDuLieu(cbo, "ERP_HOADON_NGUYENLIEU", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[7];
            header[0] = "id_nguyenlieu";
            header[1] = "id_hoadon";
            header[2] = "soluong";
            header[3] = "dongia";
            header[4] = "conlai";
            header[5] = "trangthai";
            header[6] = "ghichu";

            string[] mappingname = new string[7];
            mappingname[0] = "id_nguyenlieu";
            mappingname[1] = "id_hoadon";
            mappingname[2] = "soluong";
            mappingname[3] = "dongia";
            mappingname[4] = "conlai";
            mappingname[5] = "trangthai";
            mappingname[6] = "ghichu";

            int[] colwidth = new int[7];
            colwidth[0] = 12;
            colwidth[1] = 12;
            colwidth[2] = 24;
            colwidth[3] = 24;
            colwidth[4] = 24;
            colwidth[5] = 12;
            colwidth[6] = 900;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("ERP_HOADON_NGUYENLIEU", datagrid, csdl.OpenTable("ERP_HOADON_NGUYENLIEU", condition), header, mappingname, colwidth, 7);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_HOADON_NGUYENLIEU", "id_nguyenlieu = " + this._id_nguyenlieu + " and id_hoadon = " + this._id_hoadon);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                //this._id_nguyenlieu = Convert.ToInt32(ds.Tables[0].Rows[0]["id_nguyenlieu"].ToString().Trim());
                //this._id_hoadon = Convert.ToInt32(ds.Tables[0].Rows[0]["id_hoadon"].ToString().Trim());
                this._soluong = Convert.ToDouble(ds.Tables[0].Rows[0]["soluong"].ToString().Trim());
                this._dongia = Convert.ToDouble(ds.Tables[0].Rows[0]["dongia"].ToString().Trim());
                this._conlai = Convert.ToDouble(ds.Tables[0].Rows[0]["conlai"].ToString().Trim());
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }
        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_nguyenlieu, id_hoadon, soluong, dongia, conlai, trangthai, ghichu "
                + " from ERP_HOADON_NGUYENLIEU";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}